package com.bbt.dormassistant.controller;

import com.bbt.dormassistant.service.ImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;


@Api(tags = "照片上传接口")
@RestController
@RequestMapping("/image")
public class ImageController {

    @Autowired
    @Qualifier(value = "imageService")
    private ImageService imageService;



    @ApiOperation(value = "上传照片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "images", value = "图片",required = true, dataType = "file")
    })
    @PostMapping(value = "/addImage",consumes = "multipart/*",headers = "content-type=multipart/form-date")
    public Map uploadImage(@RequestParam(value = "images")MultipartFile image){
        Map<String,Object> map = new HashMap<>();

        map.put("imageUrl",imageService.addImage(image));
        return map;
    }



}
